package com.topica.database.task;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;

import com.topica.database.DataBaseHelper;
import com.topica.database.callback.OnGetListAnswerListener;
import com.topica.object.AnswerItem;

public class GetListAnswerTask extends TopicaDBTask {

	private static final String TAG = "GetListAnswerTask";
	private OnGetListAnswerListener listener;
	private ArrayList<AnswerItem> data;
	private String questionId;

	public GetListAnswerTask(Context context, String questionId) {
		super(context);
		data = new ArrayList<AnswerItem>();
		this.questionId = questionId;
	}

	@Override
	protected Integer doInBackground(Void... arg0) {
		DataBaseHelper myDbHelper = new DataBaseHelper(
				context.getApplicationContext());
		data = myDbHelper.getListAnswers(questionId);
		myDbHelper.close();
		return OK;
	}

	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		if (result == OK) {
			listener.onGetListAnswerListener(data);
		} else {
			Log.e(TAG, "Co loi trong qua trinh lay danh sach cau tra loi");
		}
	}

	public void setOnGetListAnswerListener(OnGetListAnswerListener listener) {
		this.listener = listener;
	}
}
